<template>
	<view style="background-color: f5f5f5;">
		<u-grid :col="5">
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
			<u-grid-item>
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片</view>
			</u-grid-item>
		</u-grid>
		<view class="wrap1">
			<u-waterfall v-model="list" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.small" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.small" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-shop">
							{{item.shop}}
						</view>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</view>
	</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				list: [],
				page_no: 1,
				page_size: 10,
			}
		},
		props: {
			"category_id": {
				type: String,
				required: true
			}
		},
		watch: {
			"category_id": {
				handler(newV) {
					this.$nextTick(() => {
						this.$refs.uWaterfall.clear();
					});
					this.page_no = 1;
					this.daodi();
				},
				immediate: true
			}
		},

		methods: {
			async addRandomData() {
				// 模拟数据加载
				uni.request({
					url: "https://api.javamall.com.cn/buyer/goods/search?page_no=" + this.page_no +
						"&page_size=" +
						this.page_size + "&category=" + this.category_id
				}).then(data => {
					if (this.page_no === 1) {
						this.list = data[1].data.data;
					} else {
						this.list = this.list.concat(data[1].data.data);
					}
					this.$emit("fuqin");
					this.page_no++;
				})
			},
			async daodi() {
				this.loadStatus = 'loading';
				await this.addRandomData();
				this.loadStatus = 'loadmore';
			}
		}
	}
</script>

<style lang="scss" scoped>
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
		.u-column {
			width: 50% !important;
		}
	}
	

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}
	
	.demo-title {
		font-size: 35rpx;
		margin-top: 5px;
		color: $u-main-color;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
	
	.demo-tag {
		display: flex;
		margin-top: 5px;
	}
	
	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}
	
	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}
	
	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}
	
	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>
